<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
	contentType="text/html; charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Ajax 练习</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
	//获得xmlHttpRequest对象
	var xmlHttp;
	try {
		//非IE、新IE
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		//IE6
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//IE5.5
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("不支持Ajax");
			}
		}

	//get异步请求
	function doGet() {
		xmlHttp.open("get", "Servlet1?username=管理员&passwd=root", true);
		xmlHttp.send();
	}

	//post异步请求
	function doPost() {
		xmlHttp.open("post", "Servlet1", true);
		xmlHttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlHttp.send("username=post管理员&passwd=post_root");
	}
</script>
</head>

<body>
	<center>
		<input type="button" value="get请求" onclick="doGet()" /> <br /> <input
			type="button" value="post请求" onclick="doPost()" />
	</center>
</body>
</html>
